<template>
  <section id="obtain-sheels">
    <div class="ObtainShells">
    <HeaderComponent :needScrollShow="true" title="福利中心" background='#ffffff' color='#000000' image_='0' size='4.8vw'>
      <template v-slot:share>
        <img class="help-icon" @click="tomybackpack" src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_help_icon.png"
          alt="" />
      </template>
    </HeaderComponent>
    <div class="top_header_title">
      <img class="poab" src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_bg.png" alt="">
      <div class="back_" @click="backAcitonFun">
        <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_fanhui_icon.png" alt="">
      </div>
      <div class="explain" @click="tomybackpack">
        <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_help_icon.png" alt="">
      </div>
      <img class="title_center" src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_title_text.png"
        alt="">
      <div class="CountingCoupons">海量点券 等你来拿</div>
    </div>
    <div class="singnIn">
      <div class="sin_top_title">
        <span>累计签到{{totalDays}}天</span>
        <div>
          <span>签到提醒</span>
          <Switch v-model="openAlert" size="20px" @change="switch_" />
        </div>
      </div>
      <div class="sign_list_qd">
        <div v-for="item,index in signList" :key="index"
          :style="item.is_today == '1' && item.status == '0'?'background: linear-gradient(180deg, #DAD6FB 0%, #FAF9FF 100%);':''">
          <span v-if="item.status == '1'" style="color:#999999">已签到</span>
          <span v-else-if="item.status == '0' && item.is_today == '1'">今日可领</span>
          <span v-else>第{{item.days}}天</span>
          <img v-if="item.days != '7'"
            src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_shell_img.png" alt="">
          <div class="img_7" v-else>
            <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/sign_shell_img.png" alt="">
            <div>
              <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/halo_img.png" alt="">
              <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/box_prize_gift.png" alt="">
            </div>
          </div>
          <span v-if="index != '6'" :style="item.status == '1'?'color:#999999':'color: #000000;'">+{{item.money}}</span>
          <div class="text_7" v-else>
            <span :style="item.status == '1'?'color:#999999':'color: #000000;'">+{{item.money}}</span>
            <span :style="item.status == '1'?'color:#999999':'color: #000000;'">神秘宝箱</span>
          </div>
        </div>
      </div>
      <div class="SignIn" @click="signIn_">
        {{status_=='1'?"今日已签到":"签到"}}
      </div>
    </div>
    <div class="shells">
      <div class="box_she">
        <div class="left_she">
          <span>我的贝壳</span>
          <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/shell_small.png" alt="">
          <span>{{gold}}</span>
        </div>
        <div class="right_she" @click="detailed">
          <span>贝壳明细</span>
          <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/fanhui_icon.png" alt="">
        </div>
      </div>
    </div>
    <div class="EarnShells">
      <Tabs v-model="active" animated>
        <Tab title="赚贝壳">
          <div class="task" v-if="singleTaskList.length"><span>单次任务</span></div>
          <div class="list_task">
            <div v-for="item,index in singleTaskList" :key="index" class="Singletask">
              <div class="left_rw">
                <div class="icon_one"><img :src="item.icon" alt="">
                </div>
                <div class="center_details">
                  <span>{{item.name}}</span>
                  <div>
                    <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/shell_small.png" alt="">
                    <span>+{{item.gold}}</span>
                  </div>
                </div>
              </div>
              <div class="right_rw">
                <div v-if="item.status==0" class="status1" @click="openapp(item.type)">
                  去完成
                </div>
                <div v-if="item.status==1" class="status2" @click="getTaskPrize('1',item.type)">
                  领取
                </div>
                <div v-if="item.status==2" class="status3">
                  已领取
                </div>
              </div>
            </div>
          </div>
          <div class="task task_two">
            <div><span>每日任务</span><span>每日进行刷新</span></div>
          </div>
          <div class="list_task">
            <div v-for="item,index in dailyTaskList" :key="index" class="Singletask">
              <div class="left_rw">
                <div class="icon_one"><img :src="item.icon" alt="">
                </div>
                <div class="center_details">
                  <span>{{item.name}}</span>
                  <div>
                    <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/shell_small.png" alt="">
                    <span>+{{item.gold}}</span>
                  </div>
                </div>
              </div>
              <div class="right_rw">
                <div v-if="item.status==0" class="status1" @click="openapp(item.type)">
                  去完成
                </div>
                <div v-if="item.status==1" class="status2" @click="getTaskPrize('2',item.type)">
                  领取
                </div>
                <div v-if="item.status==2" class="status3">
                  已领取
                </div>
              </div>
            </div>
          </div>
        </Tab>
        <Tab title="花贝壳">
          <div class="notice">
            <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/box_laba_icon.png" alt="">
            <Swipe vertical class="notice-swipe van-ellipsis" :autoplay="3000" :show-indicators="false">
              <SwipeItem v-for="item,index in lotterPrizeLog" :key="index">
                恭喜{{splice_(item.nickname)}}抽中了{{item.gift_name}}
              </SwipeItem>
            </Swipe>
          </div>
          <div class="probability" @click="probability_">
            <span>奖品概率</span>
            <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/fanhui_icon.png" alt="">
          </div>
          <div class="box_gift">
            <img v-if="lottie_" src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/box_prize_gift.png"
              alt="">
            <Vue3Lottie v-else :animationData="animationData" :loop="false" :width="380" :height="380" />
          </div>
          <div class="btn_xinyun">
            <div class="btn_gift_an" @click="lucky_chou">
              <span>幸运抽奖</span>
              <span>200贝壳开启一次</span>
            </div>

          </div>
          <div class="srcoly">
            <div class="list_prize">
              <div class="list_box" v-for="item,index in lotteryPrizeList" :key="index">
                <img :src="item.gift_pic" alt="">
                <div class="van-ellipsis" v-if="item.gift_name.length<8">
                  <div>{{item.gift_name}}</div>
                </div>
              </div>
            </div>
            <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/mengban_img.png" alt="">
          </div>
          <div class="shop_record">
            <span>兑换商店</span>
            <span @click="myexchange_1">兑换记录</span>
          </div>
          <div class="shop_duih">
            <div v-for="item,index in exchangePrizeList" :key="index" @click="exchange_shop(item)">
              <div class="gift_value">
                <img :src="item.gift_pic" alt="">
                <span>{{item.gift_name}}</span>
                <span v-if="item.money>0">{{item.money}}钻礼物</span>
              </div>
              <div class="value_lis">
                <div>
                  <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/shell_small.png" alt="">
                  <span>x{{item.gold}}</span>
                </div>
                <span>兑换</span>
              </div>
            </div>
          </div>
        </Tab>
      </Tabs>
      <div class="poab_myPrize" @click="myPrize">我的奖品</div>
    </div>
  </div>
  <Popup v-model:show="Popup" round @closed="closePopup" :close-on-click-overlay="overlayclick">
      <div class="popup_model">
        <!-- 头标 -->
        <div class="top_model_title" v-if="model_title != 'Tips'">
          <span v-if="model_title== 'shouming'">活动说明</span>
          <span v-if="model_title== 'signIn_pirze'">签到成功</span>
          <span v-if="model_title== 'conchLog'">使用记录</span>
          <span v-if="model_title== 'myPrize'">我的奖品</span>
          <span v-if="model_title== 'probability_'">奖品概率</span>
          <span v-if="model_title== 'myexchange_duix'">兑换记录</span>
          <span v-if="model_title== 'luckLottery'">恭喜获得</span>
        </div>
        <!-- 说明内容 -->
        <div class="center_miaos" v-if="model_title=='shouming'">
          <span>1、<span>每日签到：通过每日签到可以获得贝壳等虚拟奖品；</span></span>
          <span>2、<span>单次任务：单次任务获得对应贝壳；每个账号只能完成一次；</span></span>
          <span>3、<span>每日任务：完成每日任务可以获得贝壳；</span> </span>
          <span>4、<span>贝壳：贝壳可以进行奖品兑换与幸运抽奖<br /> · 装扮、礼物等奖品抽中后发放到账户中；
              <br /> · 游戏皮肤：将由客服统一发放；</span></span>
          <span>5、<span>为保证活动的公平性，不得通过任何方式作弊，一经发现将取消活动资格；</span></span>
          <span v-if="isiOS">6、<span>本活动与苹果公司无关；</span> </span>
          <span>{{isiOS?'7':'6'}}、<span>法律许可范围内，本次活动最终解释权归声贝所有。</span> </span>

        </div>
        <!-- 开启提示 -->
        <div class="SystemPrompt" v-if="model_title=='Tips'">
          <div class="ba_img">
            <div class="mode_lis">
              <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/kaiguan_img.png" alt="">
              <div>
                <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/logo.png" alt="">
                <span>快来签到领好礼~</span>
              </div>
              <span>签到赢荣耀典藏皮肤,海量点券,等你来拿~</span>
            </div>
          </div>
          <div class="tips_">
            <div>提示</div>
            <span>开启系统通知后才能开启签到提醒通知</span>
            <div @click="opensingin">去开启</div>
          </div>
        </div>
        <!-- 签到奖励 -->
        <div class="signIn_pirze" v-if="model_title=='signIn_pirze'">
          <div class="list_signin_prize" v-if="signIn_pirze.length=='1'">
            <div class="one_prize_gift">
              <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/halo_img.png" alt="">
              <img :src="signIn_pirze[0].gift_pic" alt="">
            </div>
            <span>{{signIn_pirze[0].gift_name}}</span>
            <div class="my_zdl" @click="close_model">我知道了</div>
            <span>签到第{{days}}天奖励</span>
          </div>
          <div class="list_signin_prize" v-else>
            <div class="one_prize_gift3">
              <div v-for="item,index in signIn_pirze" :key="index">
                <div class="prize_bj">
                  <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/halo_img.png" alt="">
                  <img :src="item.gift_pic" alt="">
                </div>
                <span class="van-multi-ellipsis--l2">{{item.gift_name}}</span>
              </div>
            </div>
            <div class="my_zdl" @click="close_model">我知道了</div>
            <span class="name_gift">签到第{{days}}天奖励</span>

          </div>
        </div>
        <!-- 使用记录 -->
        <div class="conchLog" v-if="model_title=='conchLog'">
          <div class="labe_header">
            <span>时间</span>
            <span>类型</span>
            <span>贝壳</span>
          </div>
          <div class="list_con1" @scroll="scrollEvent">
            <List v-model="loading" :finished="finished" :finished-text="conchLog.length<'10'?'':'没有更多了'">
              <div v-for="item,index in conchLog" :key="index" class="list_conlog">
                <span>{{item.add_time}}</span>
                <span>{{item.type}}</span>
                <span>{{item.money}}</span>
              </div>
            </List>
          </div>
        </div>
        <!-- 奖品概率 -->
        <div class="probability_" v-if="model_title=='probability_'">
          <div class="labe_header">
            <span>奖品名称</span>
            <span>中奖概率</span>
          </div>
          <div class="list_con1">
            <div v-for="item,index in lotteryPrizeList" :key="index" class="list_conlog">
              <span>{{item.gift_name}}</span>
              <span>{{item.probability}}</span>
            </div>
          </div>
        </div>
        <!-- 我的奖品 -->
        <div class="myPrize" v-if="model_title=='myPrize'">
          <div class="active_tab">
            <div :class="luckdraw =='1'?'active_':''" @click="myPrize_">我的抽奖</div>
            <div :class="luckdraw =='2'?'active_':''" @click="myexchange_">我的兑换</div>
          </div>
          <div class="labe_header" v-if="luckdraw =='1'">
            <span>奖品名称</span>
            <span>状态</span>
          </div>
          <div class="labe_header" v-else>
            <span>时间</span>
            <span>兑换奖品</span>
            <span>消耗贝壳</span>
          </div>
          <div class="list_con1" @scroll="scrollEventprize" v-if="luckdraw =='1'">
            <List v-model="loading" :finished="finished" :finished-text="luck_yDraw.length<'10'?'':'没有更多了'">
              <div v-for="item,index in luck_yDraw" :key="index" class="list_conlog">
                <span>{{item.gift_name}}</span>
                <span>{{item.status}}</span>
              </div>
            </List>
          </div>
          <div class="list_con1" @scroll="scrollEventexchange" v-else>
            <List v-model="loading" :finished="finished" :finished-text="my_exchange.length<'10'?'':'没有更多了'">
              <div v-for="item,index in my_exchange" :key="index" class="list_conlog">
                <span>{{item.add_time}}</span>
                <span>{{item.gift_name}}</span>
                <span>{{item.gold}}</span>
              </div>
            </List>
          </div>
        </div>
        <!-- 兑换记录 -->
        <div class="conchLog" v-if="model_title=='myexchange_duix'">
          <div class="labe_header" v-if="my_exchange.length">
            <span>时间</span>
            <span>兑换奖品</span>
            <span>消耗贝壳</span>
          </div>
          <div class="list_con1" @scroll="scrollEventexchange" v-if="my_exchange.length">
            <List v-model="loading" :finished="finished" :finished-text="my_exchange.length<'10'?'':'没有更多了'">
              <div v-for="item,index in my_exchange" :key="index" class="list_conlog">
                <span>{{item.add_time}}</span>
                <span>{{item.gift_name}}</span>
                <span>{{item.gold}}</span>
              </div>
            </List>
          </div>
          <div class="NoDatamy_exchange" v-else>
            <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/empty_img.png" alt="">
            <span>暂无数据</span>
          </div>
        </div>
        <!-- 恭喜获得 -->
        <div class="signIn_pirze" v-if="model_title=='luckLottery'">
          <div class="list_signin_prize">
            <div class="one_prize_gift">
              <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/halo_img.png" alt="">
              <img :src="luckLottery.gift_pic" alt="">
            </div>
            <span class="luckLo_name">{{luckLottery.gift_name}}</span>
            <span>{{luckLottery.gift_desc}}</span>
          </div>
        </div>
        <!-- 关闭按钮 -->
        <div class="model_close" @click="close_model" v-if="model_title != 'signIn_pirze'">
          <img src="https://img.xunyinjiaoyou.com/static/activity/ObtainShells/popup_close_icon.png" alt="">
        </div>
      </div>
    </Popup>
  </section>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'
import { backAciton } from '@/util/common'
import * as animationData from '@/assets/lottie/data.json'
import { signOpenAlert, signSignIn, signIndex, signConchLog, signMyPrizeLog, signMyExchangeLost, signGetTaskPrize, signLuckLottery, signExchangePrize } from '@/api/activity'
import HeaderComponent from '@/components/header_component/HeaderComponent.vue'
import { Switch, Popup, List, Tab, Tabs, Swipe, SwipeItem, Dialog } from 'vant'
import MessageBoxFun from '@/components/message_box/MessageBox'
import { Vue3Lottie } from 'vue3-lottie'
import wx from 'weixin-js-sdk'
import 'vue3-lottie/dist/style.css'
import 'vant/lib/index.css'
export default defineComponent({
    components: {
        HeaderComponent,
        Switch,
        Popup,
        List,
        Tab,
        Tabs,
        Swipe,
        SwipeItem,
        Vue3Lottie
    },
    setup () {
        const data = reactive<Record<string, any>>({
            openAlert: false, //签到
            active: 0, //0赚贝壳1花贝壳
            Popup: false, //弹窗
            model_title: '', //Tips签到提示 shouming活动说明 signIn_pirze签到奖励 conchLog签到奖励 probability_奖品概率
            dailyTaskList: [], //每日任务
            days: 0, //签到天数
            gold: 0, //我的贝壳
            exchangePrizeList: [], //奖品商店
            lotteryPrizeList: [], //奖品概率
            singleTaskList: [], //单次任务
            lotterPrizeLog: [], //中奖人员
            totalDays: '', //总签到次数
            signList: [], //签到天数
            signIn_pirze: [], //签到奖励
            page: 1, //贝壳明细分页
            conchLog: [], //贝壳明细数据
            luckLottery: {}, //抽奖奖品

            luck_yDraw: [], //我的抽奖
            my_exchange: [], //我的兑换
            loading: false,
            finished: false,
            luckdraw: '1', //1我的抽奖2我的兑换
            overlayclick: false, //默认点击遮罩层不关闭弹窗

            animationData: animationData,
            animationSpeed: 1,
            anim: {},
            lottie_: true, //true静态图false lottie
            SignInremind_: 0, //0失败1成功开启签到提醒

            // navList: [], //单次任务
            show_zi: false,
            scrollTop_zi: true,
            isiOS: false,
            status_: 0,
        })
        const backAcitonFun = ():void => {
            backAciton()
        }
        const tomybackpack = ():void => {
            data.Popup = true;
            data.model_title = "shouming"
        }
        const openAlert_ = async (status: string):Promise<void> => {
            let arys = {
            status: status
            }; //参数
            const dataRes = await signOpenAlert(arys)
            MessageBoxFun({
                message: dataRes.data.text,
                delay: 1500
            })
        }
        const signInRemind = (SignInremind_: number):void => {
            data.SignInremind_ = SignInremind_
        }
        const switch_ = (value: any):void => {
            if (value) {
                data.openAlert = false;
                if ((window as any).isiOS) {
                    (window as any).signInRemind = signInRemind;
                    (window as any).webkit.messageHandlers.signInRemind.postMessage({});
                    if (data.SignInremind_ == '1') {
                        data.openAlert = true;
                        openAlert_("1")
                    } else {
                        data.openAlert = false;
                    }
                } else {
                    let Android = (window as any).app.signInRemind()
                    if (Android == '1') {
                        data.openAlert = true;
                        openAlert_("1")
                    }
                }
            } else {
                openAlert_("0")
                data.openAlert = false;
            }
        }
        const index = async ():Promise<void> => {
            let arys = {}; //参数
            const dataRes = await signIndex(arys)
            if (dataRes.data.status == 0) {
                data.dailyTaskList = dataRes.data.result.dailyTaskList;
                data.days = dataRes.data.result.days;
                data.totalDays = dataRes.data.result.totalDays;
                data.signList = dataRes.data.result.signList;
                data.exchangePrizeList = dataRes.data.result.exchangePrizeList;
                data.gold = dataRes.data.result.gold;
                data.lotteryPrizeList = dataRes.data.result.lotteryPrizeList;
                data.singleTaskList = dataRes.data.result.singleTaskList;
                data.lotterPrizeLog = dataRes.data.result.lotterPrizeLog;
                data.status_ = dataRes.data.result.status;
                dataRes.data.result.openAlert ? data.openAlert = true : data.openAlert = false;
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                });
            }
        }
        const signIn_ = async ():Promise<void> => {
            data.overlayclick = true;
            const arys = {}; //参数
            const dataRes = await signSignIn(arys)
            if (dataRes.data.status == 0) {
                data.model_title = 'signIn_pirze',
                data.Popup = true;
                data.days = dataRes.data.result.days;
                data.signIn_pirze = dataRes.data.result.prize_list;
                index()
          } else {
            MessageBoxFun({
                message: dataRes.data.text,
                delay: 1500
            })
          }
        }
        const detailed = async(): Promise<void> => {
            const arys = {
                page: data.page,
            }; //参数
            const dataRes = await signConchLog(arys)
            if (dataRes.data.status == 0) {
                data.Popup = true;
                data.model_title = 'conchLog';
                if (dataRes.data.result.list.length) {
                data.conchLog = data.conchLog.concat(dataRes.data.result.list);
                data.page++;
                data.finished = true;
                } else {
                // 数据全部加载完成
                data.finished = true;
                }
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                })
            }
        }
        const closePopup = ():void => {
            data.page = 1;
            data.conchLog = []; //明细
            data.model_title = '';
            data.finished = true;
            data.overlayclick = false;
        }
        const close_model = ():void => {
            data.finished = true
            data.overlayclick = false
            data.Popup = false
        }
        const scrollEvent = (e: any):void => {
            if (e.srcElement.scrollTop + e.srcElement.clientHeight == e.srcElement.scrollHeight) {
            // 加载状态结束
                data.loading = true;
                data.finished = false;
                detailed()
            }
        }
        const myPrize_index = async (): Promise<void> => {
            const arys = {
                page: data.page,
            } //参数
            const dataRes = await signMyPrizeLog(arys)
            if (dataRes.data.status == 0) {
                if (dataRes.data.result.list.length) {
                    data.luck_yDraw = data.luck_yDraw.concat(dataRes.data.result.list);
                    data.page++;
                if (dataRes.data.result.list.length < 10) {
                    data.finished = true;
                }
                } else {
                    data.finished = true;
                }
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                })
            }
        }
        const myPrize_ = (): void => {
            data.page = 1;
            data.luckdraw = '1';
            data.luck_yDraw = [];
            myPrize_index();
        }
        const myexchange_index = async ():Promise<void> => {
            const arys = {
                page: data.page,
            } //参数
            const dataRes = await signMyExchangeLost(arys)
            if (dataRes.data.status == 0) {
                if (dataRes.data.result.list.length) {
                data.my_exchange = data.my_exchange.concat(dataRes.data.result.list);
                data.page++;
                if (dataRes.data.result.list.length < 10) {
                    data.finished = true;
                }
                } else {
                    data.finished = true;
                }
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                })
            }
        }
        const myexchange_ = ():void => {
            data.page = 1;
            data.luckdraw = '2';
            data.my_exchange = [];
            setTimeout(() => {
            myexchange_index()
            }, 300)
        }
        const scrollEventprize = (e: any): void => {
            if (e.srcElement.scrollTop + e.srcElement.clientHeight == e.srcElement.scrollHeight) {
                // 加载状态结束
                data.loading = true;
                data.finished = false;
                myPrize_index()
            }
        }
        const scrollEventexchange = (e: any): void => {
            if (e.srcElement.scrollTop + e.srcElement.clientHeight == e.srcElement.scrollHeight) {
                // 加载状态结束
                data.loading = true
                data.finished = false
                myexchange_index()
            }
        }
        const openapp = (type: string):void => {
            let isIOS = (window as any).isiOS;
            let tabIndex: any = "";
            if ((window as any).isWeixin) {
            if (type == "send_index") {
                tabIndex = 0
                wx.miniProgram.switchTab({url: "/pages/index/index"}); //首页
            } else if (type == "reply_record") {
                tabIndex = 1
                MessageBoxFun({
                    message: "小程序暂不支持跳转动态",
                    delay: 1500
                })
            } else if (type == "message") {
                tabIndex = 2
                wx.miniProgram.switchTab({url: "/pages/message/message"}); //消息
            } else if (type == "my_core") {
                tabIndex = 3
                wx.miniProgram.switchTab({url: "/pages/my_home/my_home"}); //我的
            } else if (type == "bind_mobile") {
                wx.miniProgram.navigateTo({url: "/pages/bindMobile/bindMobile"});//绑定手机
            } else if (type == "edit_face" || type == "edit_origin_sign") {
                wx.miniProgram.navigateTo({url: "/pages/means/means"}); //编辑
            } else if (type == "recharge") {
                wx.miniProgram.navigateTo({url: "/pages/recharge/recharge"}); //充值
            } else if (type == "join_room") {
                wx.miniProgram.navigateTo({url: "/pages/allRoom/allRoom"}); //更多房间
            }
            } else {
            if (type == "send_index") {
                tabIndex = 0
                isIOS ? (window as any).webkit.messageHandlers.selectTabIndex.postMessage({
                tabIndex: tabIndex
                }) : (window as any).app.selectTabIndex(tabIndex); //首页
            } else if (type == "reply_record") {
                tabIndex = 1
                isIOS ? (window as any).webkit.messageHandlers.selectTabIndex.postMessage({
                tabIndex: tabIndex
                }) : (window as any).app.selectTabIndex(tabIndex); //动态
            } else if (type == "message") {
                tabIndex = 2
                isIOS ? (window as any).webkit.messageHandlers.selectTabIndex.postMessage({
                tabIndex: tabIndex
                }) : (window as any).app.selectTabIndex(tabIndex); //消息
            } else if (type == "my_core") {
                tabIndex = 3
                isIOS ? (window as any).webkit.messageHandlers.selectTabIndex.postMessage({
                tabIndex: tabIndex
                }) : (window as any).app.selectTabIndex(tabIndex); //我的
            } else if (type == "bind_mobile") {
                isIOS ? (window as any).webkit.messageHandlers.bindMobile.postMessage({}) : (window as any).app.bindMobile() //绑定手机
            } else if (type == "edit_face" || type == "edit_origin_sign") {
                isIOS ? (window as any).webkit.messageHandlers.editData.postMessage({}) : (window as any).app.editData() //编辑
            } else if (type == "recharge") {
                isIOS ? (window as any).webkit.messageHandlers.pageJumpRecharge.postMessage({}) : (window as any).app.pageJumpRecharge(); //充值
            } else if (type == "join_room") {
                isIOS ? (window as any).webkit.messageHandlers.morePages.postMessage({}) : (window as any).app.morePages(); //更多房间
            }
            }
        }
        const getTaskPrize = async (type: string, taskType: string): Promise<void> => {
            const arys = {
                type: type,
                taskType: taskType
            } //参数
            const dataRes = await signGetTaskPrize(arys)
            index()
            MessageBoxFun({
                message: dataRes.data.text,
                delay: 1500
            })
        }
        const probability_ = ():void => {
            data.Popup = true
            data.model_title = "probability_"
        }
        const lucky_chou = async (): Promise<void> => {
            if (data.gold < 200) {
                return MessageBoxFun({
                    message: "贝壳不足",
                    delay: 1500
                })
            }
            data.lottie_ = false;
            let arys = {}; //参数
            const dataRes = await signLuckLottery(arys)
            if (dataRes.data.status == 0) {
                data.anim.addEventListener('complete', () => {
                    data.Popup = true;
                    data.model_title = 'luckLottery'; //抽奖
                    data.lottie_ = true;
                    data.luckLottery = dataRes.data.result
                }, 0)
                index()
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                })
            }
        }
        const myexchange_1 = ():void => {
            data.Popup = true;
            data.model_title = 'myexchange_duix';
            data.page = 1;
            data.my_exchange = [];
            myexchange_index()
        }
        const exchangePrize = async (item: Record<string, any>): Promise<void> => {
            const arys = {
                prizeId: item.id
            } //参数
            const dataRes = await signExchangePrize(arys)
            if (dataRes.data.status == 0) {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                });
                index()
            } else {
                MessageBoxFun({
                    message: dataRes.data.text,
                    delay: 1500
                });
            }
        }
        const exchange_shop = (item: Record<string, any>): void => {
            Dialog.confirm({
                title: "兑换奖品",
                message: "确认消耗" + item.gold + "贝壳兑换" + item.gift_name + "吗?",
                beforeClose,
                confirmButtonColor: "#0659FF",
                cancelButtonColor: "A8ABAE"
            })
            .then(() => {
                exchangePrize(item);
            })
            .catch(() => {
                // console.log("取消");
            });

            function beforeClose(action: any) {
                 new Promise((resolve) => {
                    setTimeout(() => {
                    if (action === 'confirm') {
                        resolve(true);
                    } else {
                        // 拦截取消操作
                        resolve(false);
                    }
                    }, 500);
                });
            }
        }
        const myPrize = ():void => {
            data.Popup = true;
            data.model_title = 'myPrize';
            myPrize_()
        }
        const splice_ = (value: string): string => {
            let slice2 = "";
            if (value.length > 6) {
                slice2 = value
                slice2 = slice2.slice(0, 5)
                return slice2 + '...';
            } else {
                return value
            }
        }
        const handleAnimation = (anim: any):void => {
            data.anim = anim;
        }
        const u = navigator.userAgent
        data.isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        index();
        return {
            tomybackpack,
            splice_,
            backAcitonFun,
            switch_,
            detailed,
            myPrize_,
            lucky_chou,
            signIn_,
            closePopup,
            close_model,
            scrollEvent,
            myexchange_,
            exchange_shop,
            scrollEventprize,
            scrollEventexchange,
            handleAnimation,
            openapp,
            getTaskPrize,
            probability_,
            myPrize,
            myexchange_1,
            ...toRefs(data)
        }
    }
})
</script>

<style lang="less" scoped>
@import './ObtainShells.less';
</style>